package top.drinyeit.nongmao.activity;

import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;


import java.util.HashMap;
import java.util.Map;

import top.drinyeit.nongmao.R;
import top.drinyeit.nongmao.app.Constant;
import top.drinyeit.nongmao.base.BaseActivity;
import top.drinyeit.nongmao.model.AuthenticationDetailBean;
import top.drinyeit.nongmao.presenter.EditCompanyPresenter;
import top.drinyeit.nongmao.util.SPUtil;

/**
 * Created by wu on 2018/1/8.
 */

public class CompanyNameActivity extends BaseActivity {
    private ImageView delete_all;//删除按钮
    public TextView nick_name, save_btn;//昵称

    private AuthenticationDetailBean authenticationDetailBean;
    private EditCompanyPresenter editCompanyPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_nickname);

        initView();
        initIntent();
        initData();
        init();
        setTitle(true,"企业名称");
    }

    private void initView() {
        delete_all = (ImageView) findViewById(R.id.delete_all);
        nick_name = (TextView) findViewById(R.id.nick_name);
        save_btn = findViewById(R.id.save_btn);
    }

    private void initIntent() {
        authenticationDetailBean = (AuthenticationDetailBean) getIntent().getSerializableExtra("a");
        nick_name.setText(authenticationDetailBean.getCompany_name());
    }

    private void initData() {
        editCompanyPresenter = new EditCompanyPresenter(this);
    }

    @Override
    public void init() {
        nick_name.setInputType(InputType.TYPE_CLASS_TEXT);
        nick_name.setHint("请输入企业名称");
        delete_all.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                nick_name.setText("");
            }
        });
        //保存
        save_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (nick_name.getText().length() == 0) {
                    showToast("企业名称不能为空");
                } else {
                    Map<String, Object> map = new HashMap<>();
                    map.put("action", "company_authentication");
                    map.put("user_id", SPUtil.getShareString(Constant.USER_ID));
                    map.put("company_name", nick_name.getText().toString());
                    editCompanyPresenter.editCompany(map);
                }

            }
        });
    }

}
